home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 142
/
Volume 142 Oct 17 2011 - Damaged.iso
/
Games
/
pocket-rocket.swf
/
scripts
/
Key.as
< prev
next >
Wrap
Text File
|
2011-10-17
|
1KB
|
59 lines
package
{
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
public class Key
{
private static var initialized:Boolean = false;
private static var keysDown:Object = new Object();
public function Key()
{
super();
}
public static function initialize(param1:Stage) : void
{
if(!initialized)
{
param1.addEventListener(KeyboardEvent.KEY_DOWN,keyPressed);
param1.addEventListener(KeyboardEvent.KEY_UP,keyReleased);
param1.addEventListener(Event.DEACTIVATE,clearKeys);
initialized = true;
}
}
private static function clearKeys(param1:Event) : void
{
keysDown = new Object();
}
public static function isDown(param1:uint) : Boolean
{
if(!initialized)
{
throw new Error("Key class has yet been initialized.");
}
return Boolean(param1 in keysDown);
}
private static function keyPressed(param1:KeyboardEvent) : void
{
keysDown[param1.keyCode] = true;
}
private static function keyReleased(param1:KeyboardEvent) : void
{
if(param1.keyCode in keysDown)
{
delete keysDown[param1.keyCode];
}
}
}
}